package com.github.common.util.lang;

public class BooleanUtil {
    private static final String[] TRUE_VALUES = {"TRUE", "1", "Y"};

    public static Boolean from(final Integer value) {
        if (value == null) {
            return null;
        }
        return value == 1;
    }

    public static Boolean from(final Integer value, final boolean defaultValue) {
        if (value == null) {
            return defaultValue;
        }
        return from(value);
    }

    public static Boolean from(final String str) {
        if (StringUtil.isEmpty(str)) {
            return null;
        }
        return StringUtil.isIn(str.toUpperCase(), TRUE_VALUES);
    }

    public static Boolean from(final String str, final boolean defaultValue) {
        if (StringUtil.isEmpty(str)) {
            return defaultValue;
        }
        return from(str);
    }

}
